const app = getApp()
var utils = require('../../untils/util.js');
Page({
  data: {
    labelList: [],
    currentPicked: 0,//点击效果样式
    currentNodeId:'',
    inputValue:'',//输入框的文字
  },
  onLoad: function () {
    var _this = this;
    wx.setNavigationBarTitle({
      title: '爱情会客厅',
    });
    this.initPage();
  },
  goChooseCityPage: function () {
    wx.navigateTo({
      url: '../../pages/chooseCity/chooseCity'
    });
  },
  initPage: function () {
    var _this = this;
    app.getUserInfo({"openId":wx.getStorageSync('openid')});
    app.doReq(app.globalData.DICTIONARY, { parentId: 1054 }, 'GET', function (res) {
      console.log(res);
      _this.setData({
        labelList: res.data.obj['1054'],
        currentNodeId:res.data.obj['1054'][0].id
      })
    });
  },
  doPick: function (e) {
    var choose = e.currentTarget.dataset.choose;
    var nodeid = e.currentTarget.dataset.nodeid;
    this.setData({
      currentPicked: choose,
      currentNodeId: nodeid,//会客地点id
    });
  },
  doSave: function (e) {
    var _this=this;
    var userInfo = wx.getStorageSync('userInfo');
    var userId = app.globalData.userid;
    if (userInfo.member.cregion.id != 5) {
      wx.showToast({
        title: '目前只针对杭州市开放，您的所在地区不符合要求！',
        icon:'none',
      })
      return;
    }
    var hkdd = _this.data.currentNodeId
    if (hkdd == '') {
      wx.showToast({
        title: '请选择会客地点！',
        icon: 'none',
      })
      return;
    }
     app.doReq(app.globalData.SERVICE.MATES.VERIFY, { id: userId }, 'GET', function (res) {
       if (res.data.errmsg.indexOf("择偶") > 0) {
         // 择偶条件没有完善跳转到择偶条件
         app.confirm("提示", "为更好地为您提供服务，请在“个人编辑”中完善择偶条件。").then(function (value) {
           if (value) {
             wx.navigateTo({
               url: '../../pages/personalBaseInfoEdit/personalBaseInfoEdit'
             })
           }
         });
       } else if (res.data.errmsg.indexOf("基本信息") > 0) {
         app.confirm("提示", "为更好地为您提供服务，请在“个人编辑”中完善个人资料。").then(function (value) {
           if (value) {
             wx.navigateTo({
               url: '../../pages/personalBaseInfoEdit/personalBaseInfoEdit'
             })
           }
         });
       } else if (res.data.errmsg.indexOf("形象照") > 0) {
         app.confirm("提示", "为更好地为您提供服务，请在“个人”中上传形象照、身份证、毕业证。").then(function (value) {
           if (value) {
             wx.navigateTo({
               url: '../../pages/personalBaseInfoEdit/personalBaseInfoEdit'
             })
           }
         });
       } else {
         app.doReq(app.globalData.SERVICE.USERCENTER.ACCOUNT_ROOM, {
          'room.basic.id':userId,
          'room.hkdd.id': hkdd,
          'room.content': _this.data.inputValue
        },'GET', function (res) {
          if (res.data.code == 200 && res.data.type === 'SUCCESS') {
            wx.showToast({
              title: '提交成功！',
              icon: 'success',
            })
            // utilities.refreshUserInfo(function (data) {
            //   history.back();
            // });
          } else {
            wx.showToast({
              title: '您已经提交过申请了，请耐心等待我们会联系您的！',
              icon: 'none',
            });
          }
        });
      }
    });
  },
  doInput:function(e){
    var value=e.detail.value;
    this.setData({
      inputValue:value,
    });
  }
})